//
//  OrderHeader.m
//  jingdongfang
//
//  Created by 郝志宇 on 16/8/11.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "OrderHeader.h"
#import "IntroViewController.h"
@interface OrderHeader () {
    UIImageView *image;
    UILabel *name;
    UILabel *state;
}

@end

@implementation OrderHeader

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self _initViews];
    }
    return self;
}

- (void)_initViews
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    image = [[UIImageView alloc] initWithFrame:CGRectZero];
    image.contentMode = UIViewContentModeScaleAspectFit;    
    [self.contentView addSubview:image];
    
    name = [[UILabel alloc] initWithFrame:CGRectZero];
    name.font = [UIFont systemFontOfSize:15];
    name.userInteractionEnabled = YES;
    [self.contentView addSubview:name];
    
    state = [[UILabel alloc] initWithFrame:CGRectZero];
    state.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:state];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toIntro)];
    [name addGestureRecognizer:tap];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    image.frame = CGRectMake(15, 0, 20, 20);
    image.centerY = self.height/2;
    if (self.isMyBuy==YES)
    {
        image.image = [UIImage imageNamed:@"my_sale"];
    }
    else
    {
        image.image = [UIImage imageNamed:@"my_sell-8"];
    }
    image.contentMode = UIViewContentModeScaleAspectFill;
    image.clipsToBounds = YES;
    
    name.text = _info.nike.length>0?_info.nike:@" ";
    [name sizeToFit];
    name.x = image.right+8;
    name.centerY = self.height/2;
    state.textColor = [UIColor appColor];

    if ([_info.type integerValue] == 1)
    {//购买电子画
        if ([_info.status integerValue]==0)
        {  //未支付
//            state.text = @"等待付款";
            state.text = NSLocalizedString(@"To be Paid", nil);
        }
         if ([_info.status integerValue]==3)
        {  //已支付
//            state.text = @"已完成";
            state.text = NSLocalizedString(@"Completed", nil);
            state.textColor = [UIColor c5Color];
        }
         if ([_info.status integerValue]==6)
        {  //未发货
//            state.text = @"订单已取消";
            state.text = NSLocalizedString(@"Canceled", nil);
            state.textColor = [UIColor c5Color];
        }
    }
    else
    {//购买艺术品或购买画屏配件
        if ([_info.status integerValue]==0)
        {  //未支付
//            state.text = @"等待付款";
            state.text = NSLocalizedString(@"To be Paid", nil);
         }
        if ([_info.status integerValue]==1)
        {  //已支付未发货
//            state.text = @"等待卖家发货";
            state.text = NSLocalizedString(@"Prepare Shipping", nil);
        }
       if ([_info.status integerValue]==2)
        {  //已发货未收货
//            state.text = _isMyBuy ? @"卖家已发货" : @"待收货";
            state.text = _isMyBuy ? NSLocalizedString(@"Delivered → Shipped", nil) : NSLocalizedString(@"To be delivered to door",nil);
        }
         if ([_info.status integerValue]==3)
        {  //已发货已收货
//            state.text = @"已完成";
            state.text = NSLocalizedString(@"Completed", nil);
            state.textColor = [UIColor c5Color];
        }
         if ([_info.status integerValue]==4)
        {  //退款
//            state.text = @"退款中";
            state.text = NSLocalizedString(@"Refunding", nil);
        }
        if ([_info.status integerValue]==5)
        {  //退款
//            state.text = @"已退款";
            state.text = NSLocalizedString(@"Refunded", nil);
            state.textColor = [UIColor c5Color];
        }
        if ([_info.status integerValue]==7)
        {
//            state.text = @"退款确认中";
            state.text = NSLocalizedString(@"Refund Confirming", nil);
        }
        if ([_info.status integerValue]==6)
        {
//            state.text=@"订单已取消";
            state.text = NSLocalizedString(@"Canceled", nil);
            state.textColor = [UIColor c5Color];
        }
    }
    [state sizeToFit];
    state.right = self.width-15;
    state.centerY = self.height/2;
    name.width = KSCREENWIDTH - name.left - state.width - 8 - 5;
}

- (void)toIntro
{
    if (_info.uId)
    {
        IntroViewController *vc = [[IntroViewController alloc] init];
        vc.u_id = _info.uId;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
}
@end
